home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 8823 / 8823.xpi / chrome / omnibar / content / lib.js < prev    next >
Text File  |  2009-09-05  |  2KB  |  77 lines

  1. var Omnibar = {
  2.      V: "0.5.4"
  3. };
  4.  
  5. if(typeof Cc === "undefined") {
  6.      var Cc = Components.classes;
  7. }
  8. if(typeof Ci === "undefined") {
  9.      var Ci = Components.interfaces;
  10. }
  11. if(typeof Cr === "undefined") {
  12.      var Cr = Components.results;
  13. }
  14. if(typeof Cu === "undefined") {
  15.      var Cu = Components.utils;
  16. }
  17.  
  18. // console for logging messages in browser's error console.
  19. if(typeof console === 'undefined') {
  20.     var console = {
  21.         log: function(o) {
  22.             Cc["@mozilla.org/consoleservice;1"]
  23.                        .getService(Ci.nsIConsoleService).logStringMessage(o+'');
  24.         }
  25.         , error: function(o) {
  26.             Cu.reportError(o+'');
  27.         }
  28.     };
  29. }
  30.  
  31. Omnibar.DeferredJob = function() {
  32. }
  33. Omnibar.DeferredJob.prototype = {
  34.      timeoutID: null,
  35.      active: false,
  36.      schedule: function(delay, fn, scope, args) {
  37.           this.cancel();
  38.           this.active = true;
  39.           this.timeoutID = setTimeout(function() {
  40.                fn.apply(scope||window, args);
  41.           }, delay);
  42.      },
  43.      cancel: function() {
  44.           this.active = false;
  45.           var timeoutID = this.timeoutID;
  46.           if(timeoutID) {
  47.                clearTimeout(timeoutID);
  48.                this.timeoutID = null;
  49.           }
  50.      }
  51. }
  52.  
  53. Omnibar.ReJob = function() {
  54. }
  55. Omnibar.ReJob.prototype = {
  56.      _threadID: null,
  57.      active: false,
  58.      start: function(interval, fn, scope, args) {
  59.           var self = this;
  60.           this.active = true;
  61.           this.stop();
  62.           this._threadID = setInterval(function() {
  63.                if(fn.apply(scope||window, args) === false) {
  64.                     self.stop();
  65.                }
  66.                
  67.           }, interval);
  68.      },
  69.      stop: function() {
  70.           this.active = false;
  71.           var threadID = this._threadID;
  72.           if(threadID) {
  73.                clearInterval(threadID);
  74.                this._threadID = null;
  75.           }
  76.      }
  77. }